<?php
declare(strict_types=1);

namespace app\admin\service\home;

use app\admin\model\AdminRole;
use app\admin\model\AdminRule;

class IndexService{

    /**
     * 管理员权限菜单
     */
    public static function getAdminMenu($admin){
        $role = AdminRole::field('rulesArr,state')->find($admin->role_id); //获取用户所在角色组
        $data =[];
        if($role->rulesArr && $role->state == 1){ //角色组是否有效
            //获取该角色组所有有效的权限菜单 type=>1 是菜单类型 state=>1 是正常的状态
            $data = AdminRule::whereIn('id',$role->rulesArr)
//                ->where('type', 1) //1菜单 0方法
                ->where('state', 1)
                ->field('id,title,name,path,icon,pid,type,sort')->order('sort', 'ASC')
                ->order('id', 'ASC')
                ->select()->toArray();
        }
        return $data;
    }

}